package com.caiden_micheal.menu.controller;

import com.caiden_micheal.base.aop.annotation.PermissionVerify;
import com.caiden_micheal.base.domain.AjxResult;
import com.caiden_micheal.menu.domain.Menu;
import com.caiden_micheal.menu.dto.IconAddDTO;
import com.caiden_micheal.menu.dto.IconPageQueryDTO;
import com.caiden_micheal.menu.service.MenuService;
import com.caiden_micheal.menu.vo.DeleteMenuVO;
import com.caiden_micheal.menu.vo.UpdateIndexVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @PermissionVerify(permissionArray = {"sys:menuManagement:edit"})
    @PostMapping("/updateMenuIndex")
    public AjxResult updateIndex(@RequestBody UpdateIndexVO data) {
        return menuService.updateIndex(data);
    }

    @PostMapping("/iconQueryCondition")
    public AjxResult iconQueryCondition(@RequestBody IconPageQueryDTO iconPageQueryDTO) {
        return AjxResult.success(menuService.iconPageQuery(iconPageQueryDTO));
    }

    @PermissionVerify(permissionArray = {"sys:menuManagement:add", "sys:menuManagement:edit"})
    @PostMapping("/addIcon")
    public AjxResult iconAdd(@RequestBody IconAddDTO iconAddDTO) {
        return menuService.addIcon(iconAddDTO);
    }

    @PermissionVerify(permissionArray = {"sys:menuManagement:add"})
    @PostMapping("/addMenu")
    public AjxResult addMenu(@RequestBody Menu menu) {
        return menuService.addMenu(menu);
    }

    @PermissionVerify(permissionArray = {"sys:menuManagement:edit"})
    @PostMapping("/editMenu")
    public AjxResult editMenu(@RequestBody Menu menu) {
        return menuService.editMenu(menu);
    }

    @PermissionVerify(permissionArray = {"sys:menuManagement", "sys:userManagement:permissionView", "sys:permissionManagement"})
    @PostMapping("/findAllMenu")
    public AjxResult findAllMenu() {
        return menuService.findAllMenu();
    }

    @PermissionVerify(permissionArray = {"sys:menuManagement:delete"})
    @PostMapping("/removeMenu")
    public AjxResult removeMenu(@RequestBody DeleteMenuVO deleteMenuVO) {
        return menuService.removeMenu(deleteMenuVO.getId());
    }
}
